package com.zoweunion.mechanic.controller.base;

import com.alibaba.fastjson.JSONObject;
import com.zoweunion.mechanic.controller.BaseController;
import com.zoweunion.mechanic.model.ResponseBean;
import com.zoweunion.mechanic.service.base.KanBanService;
import com.zoweunion.mechanic.util.constants.Constants;
import com.zoweunion.mechanic.util.MyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@SuppressWarnings("unchecked")
@RestController
public class KanBanController extends BaseController{

	@Autowired
	private KanBanService kanBanService;
	/**
	 *  工单金额统计
	 */
	@PostMapping("/workOrderAmount")
	public ResponseBean workOrderAmount(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "工单金额统计");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		Map<String,  Object> resultMap;
		try {
			Thread.sleep(3000);
			resultMap = kanBanService.workOrderAmount(reqMap);
		} catch (Exception e) {
			e.printStackTrace();
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
		}
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 *  修工金额统计
	 */
	@PostMapping("/repairAmount")
	public ResponseBean repairAmount(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "修工金额统计");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		Map<String, Object> resultMap;
		try {
			resultMap = kanBanService.repairAmount(reqMap);
		} catch (Exception e) {
			e.printStackTrace();
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
		}
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}


	/**
	 * 获取所有修工
	 */
	@PostMapping("/getXgListInfo")
	public ResponseBean getXgListInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "获取所有修工");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		List<Map<String,  Object>> resultMap;
		try {
			resultMap = kanBanService.getXgListInfo(reqMap);
		} catch (Exception e) {

			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");

		}

		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}
	
	/**
	 * 获取综合看板信息
	 */	
	@PostMapping("/getKanBanInfo")
	public ResponseBean getKanBanInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "获取看板信息");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		Map<String,  Object> resultMap;
		try {
			resultMap = kanBanService.getKanBanInfo(reqMap);
		} catch (Exception e) {
			
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
				
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}
	
	/**
	 * 获取营收日统计信息
	 */	
	@PostMapping("/getYingShouInfo")
	public ResponseBean getYingShouInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "获取营收日统计信息");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		Map<String, Object> resultMap;
		try {
			
			resultMap = kanBanService.getYingShouInfo(reqMap);
			
		} catch (Exception e) {
			
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
		
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}
	
	/**
	 * 获取营收周统计信息
	 */	
	@PostMapping("/getWeekYingShouInfo")
	public ResponseBean getWeekYingShouInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "获取营收周统计信息");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		List<Map<String, Object>> resultMap;
		try {
			
			resultMap = kanBanService.getWeekYingShouInfo(reqMap);
			
		} catch (Exception e) {
			
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
		
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}
	
	/**
	 * 获取营收月统计信息
	 */	
	@PostMapping("/getYueYingShouInfo")
	public ResponseBean getYueYingShouInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "获取营收月统计信息");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		Map<String, Object> resultMap;
		try {
			
			resultMap = kanBanService.getYueYingShouInfo(reqMap);
			
		} catch (Exception e) {
			
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
		
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}
	
	/**
	 * 三包配件预测统计信息 b
	 */	
	@PostMapping("/getPartsPridicateInfo")
	public ResponseBean getPartsPridicateInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "三包配件预测统计信息");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		List<Map<String, Object>> resultList = null;
		try {
			
			resultList = kanBanService.getPartsPridicateInfo(reqMap);
			
		} catch (Exception e) {
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
		
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultList);
	}
	
	/**
	 * 配件销量排行榜 y
	 */	
	@PostMapping("/getPartsSalesInfo")
	public ResponseBean getPartsSalesInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "配件销量排行榜");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		List<Map<String, Object>> resultList = null;
		try {
			
			resultList = kanBanService.getPartsSalesInfo(reqMap);
			
		} catch (Exception e) {
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
		
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultList);
	}
	
	/**
	 * 差评统计 y
	 */	
	@PostMapping("/getChaPingInfo")
	public ResponseBean getChaPingInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "差评统计");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		List<Map<String, Object>> resultList = null;
		try {
			
			resultList = kanBanService.getChaPingInfo(reqMap);
			
		} catch (Exception e) {
			
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
		
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultList);
	}
	
	/**
	 * 故障类型统计 y
	 */	
	@PostMapping("/getDictionariesInfo")
	public ResponseBean getDictionariesInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "故障类型统计");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		List<Map<String, Object>> resultList = null;
		try {
			
			resultList = kanBanService.getDictionariesInfo(reqMap);
			
		} catch (Exception e) {
			
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
		
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultList);
	}
	
	/**
	 * 客户信息统计
	 */	
	@PostMapping("/getContactInfo")
	public ResponseBean getContactInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "客户信息统计");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		List<Map<String, Object>> resultList = null;
		try {
			
			resultList = kanBanService.getContactInfo(reqMap);
			
		} catch (Exception e) {
			
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
		
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultList);
	}
	
	/**
	 * 工时信息统计
	 */	
	@PostMapping("/getWorkHoursInfo")
	public ResponseBean getWorkHoursInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "工时信息统计");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		List<Map<String, Object>> resultList = null;
		try {
			
			resultList = kanBanService.getWorkHoursInfo(reqMap);
			
		} catch (Exception e) {
			
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
		
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultList);
	}

	/**
	 * 工时信息统计
	 */
	@PostMapping("/getWorkHoursInfoNew")
	public ResponseBean getWorkHoursInfoNew(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "工时信息统计");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		List<Map<String, Object>> resultList = null;
		try {

			resultList = kanBanService.getWorkHoursInfoNew(reqMap);

		} catch (Exception e) {

			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");

		}

		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultList);
	}
	
	/**
	 * 客服管理信息统计 y
	 */	
	@PostMapping("/getKfManageInfo")
	public ResponseBean getKfManageInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "客服管理信息统计");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		List<Map<String, Object>> resultList = null;
		try {
			
			resultList = kanBanService.getKfManageInfo(reqMap);
			
		} catch (Exception e) {
			e.printStackTrace();
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
		
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultList);
	}
	
	/**
	 * 仓管管理信息统计 y
	 */	
	@PostMapping("/getCgManageInfo")
	public ResponseBean getCgManageInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "仓管管理信息统计");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		List<Map<String, Object>> resultList = null;
		try {
			
			resultList = kanBanService.getCgManageInfo(reqMap);
			
		} catch (Exception e) {
			e.printStackTrace();
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
		
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultList);
	}
	
	/**
	 * 听诊管理信息统计 y
	 */	
	@PostMapping("/getTzManageInfo")
	public ResponseBean getTzManageInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "听诊管理信息统计");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		List<Map<String, Object>> resultList = null;
		try {
			
			resultList = kanBanService.getTzManageInfo(reqMap);
			
		} catch (Exception e) {

			System.out.println("错误信息:"+e.getMessage());
			logger.debug(e.getMessage());
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
		
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultList);
	}
	
	/**
	 * 修工管理信息统计 y
	 */	
	@PostMapping("/getXgManageInfo")
	public ResponseBean getXgManageInfo(@RequestBody String str,HttpServletRequest request) throws MyException{
		logBefore(logger, "修工管理信息统计");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		List<Map<String, Object>> resultList = null;
		try {
			
			resultList = kanBanService.getXgManageInfo(reqMap);
			
		} catch (Exception e) {
			System.out.println("错误信息"+e.getMessage());
			e.printStackTrace();
			throw  new MyException(Constants.CODE_HANDEL_FAILED,"加载页面失败");
			
		}
		
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultList);
	}
	
	/**
	 * 测试mysql数据源
	 */
//	@PostMapping("/test")
//	public ResponseBean test(@RequestBody String str,HttpServletRequest request) throws MyException{
//		logBefore(logger, "测试mysql数据源");
//		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
//
//		int i = testService.insert(reqMap);
//
//		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",i);
//	}
}
